package com.iccaplayer;

import com.example.iccaplayer.R;
import com.example.iccaplayer.R.layout;
import com.example.iccaplayer.R.menu;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SettingBpmActivity extends Activity {
	private static String TAG = "SettingBpmActivity";
	
	Intent mainIntent;
	Bundle extras;
	
	EditText bpmText;
	Button plusBpmBtn, minusBpmBtn;
	Button okBtn, cancelBtn;
	
	int bpm;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting_bpm);
		
		mainIntent = getIntent();
		extras = mainIntent.getExtras();
	
		bpmText = (EditText)findViewById(R.id.BPMEditText);
		plusBpmBtn = (Button)findViewById(R.id.PlusBtn);
		minusBpmBtn = (Button)findViewById(R.id.MinusBtn);	
		okBtn = (Button)findViewById(R.id.BPMOkBtn);
		cancelBtn = (Button)findViewById(R.id.BPMCancelBtn);

		Log.d(TAG, "hi");
		if(extras != null){
			bpm = extras.getInt("BPM");
			bpmText.setText(bpm + "");
		}
		
		plusBpmBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {		
				bpm++;
				bpmText.setText(bpm + "");
			}
		});
		
		minusBpmBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {		
				bpm--;
				bpmText.setText(bpm + "");
			}
		});		
		
		okBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				bpm = Integer.parseInt(bpmText.getText() + "");
				
				mainIntent.putExtra("Bpm", bpm);
				setResult(RESULT_OK, mainIntent);
				finish();
			}
		});
		
		cancelBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				setResult(RESULT_CANCELED);
				finish();
			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.setting_bpm, menu);
		return true;
	}

}
